# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: 政务平台.py
"""

import requests
import requests



import requests
import ddddocr

def img_read():
    session = requests.session()
    ocr = ddddocr.DdddOcr()
    headers= {
    "Cookie": "JSESSIONID=DC32594281A84B1E245BA1A3DA440DF6; HWWAFSESID=803a588dbd8a1804e9; HWWAFSESTIME=1657115009959; JMOPENSESSIONID=d04d42e1-e757-4b46-aaa4-8c6fb5f88a72",
}
    session.headers = headers
    res = session.get('http://app.gjzwfw.gov.cn/jmopen/verifyCode.do?width=100&height=55&random=0.08462383677727381').content
    with open('ss.png','wb') as ffff:
        ffff.write(res)
    red = ocr.classification(res)
    return red


def ocr_img():
    session = requests.session()
    # 头部参数 顺序  反爬虫
    headers = {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Length": "9",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Cookie": "JSESSIONID=DC32594281A84B1E245BA1A3DA440DF6; HWWAFSESID=803a588dbd8a1804e9; HWWAFSESTIME=1657115009959; JMOPENSESSIONID=d04d42e1-e757-4b46-aaa4-8c6fb5f88a72",
    "Host": "app.gjzwfw.gov.cn",
    "Origin": "http://app.gjzwfw.gov.cn",
    "Pragma": "no-cache",
    "Referer": "http://app.gjzwfw.gov.cn/jmopen/webapp/html5/hnsbswdcx/index.html",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
}
    url = 'http://app.gjzwfw.gov.cn/jmopen/checkValiCode.do'
    s = img_read()
    session.headers = headers
    print(s.lower())
    data = {
        "code": s.lower()
    }
    res = session.post(url,data=data)
    print(res.text)

ocr_img()


def get_data():

    headers = {
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive",
        "Content-Length": "0",
        "Origin": "http://app.gjzwfw.gov.cn",
        "Pragma": "no-cache",
        "Referer": "http://app.gjzwfw.gov.cn/",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
    }
    url = "http://apis.zwfw.hunan.gov.cn/H006/custom/search/addressn"
    params = {
        "jz": "1",
        "sz": "430100",
        "qx": "430121"
    }
    response = requests.post(url, headers=headers, params=params, verify=False)

    print(response.text)
    print(response)